package org.example.base.clsloader;

import java.net.URL;
import java.net.URLClassLoader;

public class FooClassLoader extends ClassLoader {

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        return super.loadClass(name);
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        System.out.println("find class");
        return super.findClass(name);
    }

    public static void main(String[] args) throws ClassNotFoundException {
//        URLClassLoader appClassLoader = (URLClassLoader)ClassLoader.getSystemClassLoader();
//        System.out.println("应用(系统)类加载器 的加载路径: ");
//        URL[] urls = appClassLoader.getURLs();
//        for (URL url : urls) {
//            System.out.println(url);
//        }

        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        System.out.println("contextClassLoader = " + contextClassLoader);
        FooClassLoader fooClassLoader = new FooClassLoader();
//        Class<?> aClass = fooClassLoader.loadClass("java.lang.String");
        Class<?> aClass = fooClassLoader.loadClass("com.my.Foo");
        System.out.println("aClass = " + aClass);
    }
}
